/*
 * DTipoData.java
 *
 * Created on 8 de octubre de 2007, 05:20 PM
 */
package ig.formato.gui.app;

import javax.swing.JOptionPane;

/**
 *
 * @author  jsanchez
 */
public class DTipoData extends javax.swing.JDialog {

    String tipo = null;
    private String nombre;
    /** Creates new form DTipoData */

    public DTipoData(java.awt.Frame parent,String name,boolean editable) {
        super(parent, true);
        initComponents();

        java.awt.Dimension dimensionScreen = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Rectangle dimensionPantalla = getBounds();
        setLocation((dimensionScreen.width - dimensionPantalla.width) / 2, (dimensionScreen.height - dimensionPantalla.height) / 2);
        this.TNombre.setText(name);
        this.TNombre.setEditable(editable);
        this.TNombre.setSelectionStart(0);
        this.TNombre.setSelectionEnd(this.TNombre.getText().length());
        setVisible(true);
    }

    public String getNombre() {
        return nombre;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        CTipo = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        TNombre = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Dialog", 0, 11));
        jLabel1.setText(org.openide.util.NbBundle.getMessage(DTipoData.class, "DTipoData.jLabel1.text")); // NOI18N

        CTipo.setFont(new java.awt.Font("Dialog", 0, 11));
        CTipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Caracter", "Fecha", "Numerico" }));

        jButton1.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
        jButton1.setText(org.openide.util.NbBundle.getMessage(DTipoData.class, "DTipoData.jButton1.text")); // NOI18N
        jButton1.setSelected(true);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Dialog", 0, 11)); // NOI18N
        jButton2.setText(org.openide.util.NbBundle.getMessage(DTipoData.class, "DTipoData.jButton2.text")); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jLabel2.setText(org.openide.util.NbBundle.getMessage(DTipoData.class, "DTipoData.jLabel2.text")); // NOI18N

        TNombre.setText(org.openide.util.NbBundle.getMessage(DTipoData.class, "DTipoData.TNombre.text")); // NOI18N
        TNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TNombreActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(TNombre, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, CTipo, 0, 153, Short.MAX_VALUE))
                        .addContainerGap())
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jButton2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 90, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(25, 25, 25))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(TNombre, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(CTipo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButton1)
                    .add(jButton2))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        tipo = null;
        this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        this.tipo = CTipo.getSelectedItem().toString();
        this.nombre = TNombre.getText();
        if (this.nombre!=null && !this.nombre.trim().equals("")) {
            if (nombre.equals("SIGNO") || nombre.equals("SUBCUENTA") || nombre.equals("TIPO") || nombre.equals("CODIGO") || nombre.equals("PALABRA_CLAVE") || nombre.equals("COLUMNA") || nombre.equals("TIPO_DE_REGISTRO") || nombre.equals("TOTAL_REG_REPORTADOS") || nombre.equals("NUMERO_DE_SECUENCIA") || nombre.equals("PATRIMONIO_FIDEICOMISO") || nombre.equals("GRUPO_PORTAFOLIO") || nombre.equals("FECHA_CORTE")) {
                JOptionPane.showMessageDialog(this, "El nombre " + nombre + " es un nombre del sistema.\nCambielo por otro nombre");
            } else {
                this.dispose();
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    private void TNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TNombreActionPerformed
        this.jButton1ActionPerformed(null);
    }//GEN-LAST:event_TNombreActionPerformed

    public String getTipo() {
        return tipo;
    }

    /**
     * @param args the command line arguments
     */
    //    public static void main(String args[]) {
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                DTipoData dialog = new DTipoData(new javax.swing.JFrame(), true);
//                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
//                    public void windowClosing(java.awt.event.WindowEvent e) {
//                        System.exit(0);
//                    }
//                });
//                dialog.setVisible(true);
//            }
//        });
//    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox CTipo;
    private javax.swing.JTextField TNombre;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

}
